package com.cndw.kungfu.model.battle;

import com.cndw.kungfu.config.ConstantsIntKey;
import com.cndw.kungfu.domain.Player;
import com.cndw.kungfu.ext.NumberProcesser;
import com.cndw.kungfu.model.Context;
import com.cndw.kungfu.model.player.domain.Dragon;
import com.cndw.kungfu.model.player.domain.Office;
import com.cndw.kungfu.model.skill.PlayerSkill;
import com.cndw.kungfu.model.skill.SkillGird;
import com.cndw.kungfu.vo.battlevo.TeamPlayerVO;

/**
 * 玩家战斗对象
 * 
 * @author fantadust
 * @date 2011-4-28 下午02:50:33
 */
public class FighterPlayer extends FighterBase implements Fighter,ISkillGird {

	private Player sourceObject;

	public FighterPlayer(Player player) {
		sourceObject = player;
	}
	public FighterPlayer(Player player,int buffCoefficient){
		sourceObject = player;
		this.buffCoefficient = buffCoefficient;
		if (buffCoefficient != 0 ) {
			fixAttack = NumberProcesser.percentOnlyAddValue(sourceObject.getAttack(), buffCoefficient);
			fixDefense = NumberProcesser.percentOnlyAddValue(sourceObject.getDefense(), buffCoefficient);
			fixHit = NumberProcesser.percentOnlyAddValue(sourceObject.getHit(), buffCoefficient);
			fixDodge = NumberProcesser.percentOnlyAddValue(sourceObject.getDodge(), buffCoefficient);
			fixCrit = NumberProcesser.percentOnlyAddValue(sourceObject.getCrit(), buffCoefficient);
			fixTough = NumberProcesser.percentOnlyAddValue(sourceObject.getTough(), buffCoefficient);
		}		
		
	}

	@Override
	public long getUniqueId() {
		return sourceObject.getPlayerId();
	}

	@Override
	public String getName() {
		return sourceObject.getPlayerName();
	}

	@Override
	public int getHp() {
		return sourceObject.getHp();
	}

	@Override
	public int getMp() {
		return sourceObject.getMp();
	}

	@Override
	public int getMaxHp() {
		return sourceObject.getMaxHp();
	}

	@Override
	public int getMaxMp() {
		return sourceObject.getMaxMp();
	}

	@Override
	public int getLevel() {
		return sourceObject.getLevel();
	}

	@Override
	public int getAttack() {
		return sourceObject.getAttack() + fixAttack;
	}

	@Override
	public int getDefense() {
		return sourceObject.getDefense() + fixDefense;
	}

	@Override
	public int getHit() {
		return sourceObject.getHit() + fixHit;
	}

	@Override
	public int getDodge() {
		return sourceObject.getDodge() + fixDodge;
	}

	@Override
	public int getCrit() {
		return sourceObject.getCrit() + fixCrit;
	}

	@Override
	public int getTough() {
		return sourceObject.getTough() + fixTough;
	}

	@Override
	public Player getSourceObject() {
		return sourceObject;
	}

	/**
	 * 重写获取攻速的方法
	 */
	@Override
	public int getSpeed() {
		return sourceObject.getAttackSpeed();
	}

	/**
	 * 设置血量
	 * 
	 * @param alter
	 */
	@Override
	public synchronized void alterHp(int alter) {
		int newHp = NumberProcesser.between(alter + getHp(), 0, getMaxHp());
		sourceObject.setHp(newHp);
	}

	/**
	 * 设置魔法量
	 * 
	 * @param alter
	 */
	@Override
	public synchronized void alterMp(int alter) {
		int newMp = NumberProcesser.between(alter + getMp(), 0, getMaxMp());
		sourceObject.setMp(newMp);
	}

	@Override
	public int getHurtAdd() {
		return sourceObject.getHurtAdd();
	}

	@Override
	public int getHurtRemove() {
		return sourceObject.getHurtRemove();
	}

	@Override
	public int getHurtReflex() {
		return sourceObject.getHurtReflex();
	}

	@Override
	public int getHurtAbsorb() {
		return sourceObject.getHurtAbsorb();
	}

	@Override
	public int getCritAdd() {
		return sourceObject.getCritAdd();
	}

	@Override
	public int getSceneId() {
		return sourceObject.getSceneId();
	}

	@Override
	public TeamPlayerVO toVO() {
		return sourceObject.toTeamPlayerVO();
	}
	@Override
	public SkillGird getSkillGird(int nowStep) {
		PlayerSkill playerSkill = Context.getSkillServer().getPlayerSkill(sourceObject.getPlayerId());
		if (playerSkill == null) {
			return null;
		}
		SkillGird skillGird = playerSkill.getSkillGird(nowStep, getMp());		
		return skillGird;
	}
	@Override
	public int getScoreCHK() {
		return sourceObject.getScore();
	}
	@Override
	public int getHurtCoffAdd(){
		int hurtCoffAdd = 0;
		try {
			int officeLv = sourceObject.getDataInfo().intDataGet(ConstantsIntKey.office);
			if (officeLv >= 1) {
				hurtCoffAdd += Office.getHurtCoffByLv(officeLv);
			}
			int lw =sourceObject.getDataInfo().intDataGet(ConstantsIntKey.lw);
			if (lw >=  1) {
				hurtCoffAdd += Dragon.getOne(lw).getAddsVar()[4] * 10 ;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

		return hurtCoffAdd;
	}
	@Override
	public int getHurtCoffRemove(){
		int hurtCoffRemove = 0;
		try {
			int lw =sourceObject.getDataInfo().intDataGet(ConstantsIntKey.lw);
			if (lw >=  1) {
				hurtCoffRemove += Dragon.getOne(lw).getAddsVar()[5] * 10 ;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return hurtCoffRemove;
		
	}
	


}
